/**
 * @param {number} neededApples
 * @return {number}
 */
 var minimumPerimeter = function(neededApples) {
    const check = (m) => {
        const x = getNum(m)
        console.log(x)
        return x >= neededApples
    }
    const getNum = (m) => {
        const x = -m/2n >> 0n
        const y = m/2n 
        const cnt = BigInt((y-x+1n) >> 0n)
        return (cnt+2n)*4n-8n
    }
    let l = 2n, r = BigInt(1e15)
    while(l < r){
        const m = (l+r) >> 1n
        if(check(m)){
            r = m
        }else{
            l = m+1n
        }
    }
    return l*4n
};